package com.sikaryofficial.backend.config;

import com.sikaryofficial.system.api.model.infomation.MyStatisticsClosedVO;
import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Configuration;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author : qinjinyuan
 * @desc : MyStatisticsClosedConfig
 * @date : 2023/10/31 16:51
 */
@Configuration
@RefreshScope
@ConfigurationProperties(prefix = "hismk.backend")
@Getter
@Setter
public class MyStatisticsClosedConfig {
    /**
     * 方法名，值
     */
    private List<MyStatisticsClosedVO> myStatisticsOpenList;

    public boolean getOpenByFiledName(String fieldName) {
        return myStatisticsOpenList.stream().filter(item -> item.getFieldName().equalsIgnoreCase(fieldName)).findFirst()
                .orElse(new MyStatisticsClosedVO()).isHasOpen();
    }

    public MyStatisticsClosedVO getByFiledName(String fieldName) {
        return myStatisticsOpenList.stream().filter(item -> item.getFieldName().equalsIgnoreCase(fieldName)).findFirst()
                .orElse(new MyStatisticsClosedVO());
    }

    public boolean checkFiledNameExist(String fieldName) {
        return myStatisticsOpenList.stream().map(MyStatisticsClosedVO::getFieldName).collect(Collectors.toList())
                .contains(fieldName);
    }

}
